This document was created during the 2020 NABs R Markdown workshop and will serve as an example workflow for my future use of R Markdown. This document will represent an exploratory analysis of macroinvertebrate metrics and environmental variable associated with Cazenovia Lake.
Import Zachary M. Smith’s thesis data provided by Zachary M. Smith at the R Markdown Crash Course Workshop on March 3rd, 2020.
unique_id (character) unique sample IDlake (character) lake code: caz = Cazenovia lake, onon = Onondaga, and ot = Otiscolat (numeric) latitude of sampling locationlong (numeric) longitude of sampling locationsubstrate_size_d50 (numeric) median partical size from pebble countconductivity (numeric) specific conductivity (µS/cm)richness (numeric) taxonomic richnessshannon (numeric) Shannon-Wiener diversity index valuespct_ephemeroptera (numeric) relative abundance of Ephemeroptera taxapct_amphipoda (numeric) relative abundance of Amphipoda taxapct_diptera (numeric) relative abundance of Diptera taxadom_1 (numeric) relative abundance of the most dominant taxon observed in each samplethesis.df <- read.csv(file.path(here::here(),
"data",
"zms_thesis_metrics.csv"),
stringsAsFactors = FALSE)
Load the tidyverse packages into the global environment.
library(tidyverse)
thesis.df <- thesis.df %>%
mutate(lake = case_when(
lake %in% "caz" ~ "Cazenovia",
lake %in% "onon" ~ "Onondaga",
lake %in% "ot" ~ "Otisco",
TRUE ~ "ERROR"
),
lake = factor(lake, levels = c("Onondaga",
"Otisco",
"Cazenovia")))
thesis.df <- thesis.df %>%
filter(lake %in% params$lake)
For more details about the DT package visit https://rstudio.github.io/DT/.
library(DT)
datatable(thesis.df, options = list(scrollX = TRUE))
For more details about the leaflet package visit https://rstudio.github.io/leaflet/.
library(leaflet)
pal <- colorFactor(c("#619Cff", "#F8766D", "#00BA38"),
domain = c("Cazenovia", "Onondaga", "Otisco"))
leaflet(data = thesis.df,
options = leafletOptions(minZoom = 7,
maxZoom = 13)) %>%
addTiles() %>%
addCircleMarkers(~long, ~lat,
fillOpacity = 0.75,
fillColor = ~pal(lake),
stroke = FALSE,
popup = paste("Sample ID:", thesis.df$unique_id, "<br/>",
"Lake:", thesis.df$lake, "<br/>",
"Latitude:", thesis.df$lat, "<br/>",
"Longitude:", thesis.df$long)
)
For more details about the plotly package visit https://plot.ly/ggplot2/.
library(plotly)
scatter.plot <- ggplot(thesis.df, aes(substrate_size_d50, pct_diptera)) +
geom_point(aes(color = lake)) +
geom_smooth(method = "lm")
ggplotly(scatter.plot)
ggplot(thesis.df, aes(lake, richness, fill = lake)) +
geom_boxplot()